<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
    <script src="../scripts/jquery.min.js"></script>
    <script src="../js/jquery-form.js"></script>

    <title>图标信息添加</title>
    <style>
        body{padding: 10px;}
        .change_size{
            height: 200px;
        }
    </style>
</head>

<body>

<input type="hidden" id="flag_manager" value=<%=session.getAttribute("flag_manager")%> />


<input type="hidden" id="flag_add" value="no" />
<input type="hidden" id="curr_add_rows" value="0" />
<form  class="layui-form layui-form-pane1" id="subform" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">标识名称</label>
        <div class="layui-input-block">
            <input type="text" id="icon_name" name="icon_name" lay-verify="required|title"  placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图标类型</label>
        <div class="layui-input-block">
            <select id="icon_class" name="icon_class" lay-filter="adminRole" >
                <option value="">请选择类型</option>
                <option value="禁令标志">禁令标志</option>
                <option value="警告标志">警告标志</option>
                <option value="指示标志">指示标志</option>
                <option value="指路标志">指路标志</option>
                <option value="交通手势信号">交通手势信号</option>
                <option value="旅游区标志">旅游区标志</option>
                <option value="道路施工安全标志">道路施工安全标志</option>
                <option value="辅助标志">辅助标志</option>
                <option value="其它标志">其它标志</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea id="icon_des" name="icon_des" placeholder="请输入内容或上传文件（优先选择文件）" class="layui-textarea change_size"></textarea>
        </div>
    </div>

    <div>
        <div style="float: left;">
            <div class="layui-form-item">
                <label class="layui-form-label">上传文件</label>
                <div class="layui-input-block">
                    <input type="file" name="file_content" id="file_content" accept="text/plain" />
                </div>
            </div>
        </div>

        <div style="float: right;">
            <div class="layui-form-item">
                <label class="layui-form-label">上传图片</label>
                <div class="layui-input-block">
                    <input type="file" name="file_img" id="file_img" accept="image/*" />
                </div>
            </div>
        </div>

    </div>



</form>
<br>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" id="add_btn" onclick="to_submit()" >立即添加</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</div>


<script>
    //加载layui信息
    layui.use('form', function(){
        var form = layui.form;
        //layui日期选择
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#createTime', //指定元素
                value: new Date()
            });
        });
    });

    var layer;
    layui.use('layer', function(){
        layer = layui.layer;

    })

    var submit_times=0;
    function to_submit(){
        var icon_name=$("#icon_name").val();
        var icon_class=$("#icon_class").val();

        if(icon_name==""){
            layer.msg("名称不能为空");
            return ;
        }
        if(icon_class==""){
            layer.msg("您还没有选择类型");
            return ;
        }
        if($("#flag_manager").val()!="null"){
            ajaxFile("${pageContext.request.contextPath}/icon/icon_table_add_with_file.do");
        }else{
            layer.msg("添加失败，您不是管理员");
        }

    }
    function ajaxFile(url){

        $("#subform").ajaxSubmit({
            url:url,
            type:"post",
            enctype:'multipart/form-data',
            success:function(data){
                $("#flag_add").val("yes");
                layer.msg("一条数据已成功添加到数据库",{icon:1});
                $("#icon_des").val(data.str);
                submit_times++;
                $("#curr_add_rows").val(submit_times);
            }
        })
    }

</script>

</body>
</html>
